﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace Utilities
{
    public class ForeachTask : TaskBase
    {
        /// <summary>
        /// The task to execute for each item
        /// </summary>
        public TaskBase ItemTask { get; set; }

        protected override TaskData Execute(Job job, TaskData input)
        {
            PreCondition.RequireNotNull(ItemTask, "ItemTask");

            foreach (object item in (ICollection)input.Data)
            {
                TaskData itemInput = new TaskData
                {
                    Data = item
                };

                ItemTask.Run(job, itemInput);
            }

            return null;
        }
    }
}
